#ifndef PROJECTDATABASAOPERATIONS_H
#define PROJECTDATABASAOPERATIONS_H

#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>

extern bool connectProjectDB(QString dbName);

extern bool initProjectDB();

extern bool insertBuilding(int buildingID, QString buildingName, QString buildingDescribe, int num,
                      int upID, int type);

extern bool insertDevice(int deviceID, int productID, int buildingID, QString name, QString PA, QString appProgram, int adr, int prg, 
               int par, int grp, int cfg, QString manufacturers, QString orderNum, 
               QString product, QString unitType, QString manufacturesData, QString version, QString dbName, QString SN, QString describe);

extern bool insertAddress(int addressID, int value, QString name, QString describe, int upID, 
                            QString address, int productID, int deviceID, int eepromAddress, int addressNum,int type);

extern bool insertRelation(int relationID, int productID, int deviceID, int relationEepromAddress, 
                           int relationNum, int commObjectNum, int addressNum);

extern bool deleteBuildingByID(int buildingID);

extern bool deleteBuildingByName(QString name);

extern bool deleteDeviceByID(int deviceID);

extern bool deleteAllDeviceDataByDeviceID(int deviceID);

extern bool deleteAddressByID(int addressID);

extern bool deleteAddressByAddressAndType(QString address, int type);

extern bool deleteAddressByDeviceIDAndGAAndType(int deviceID, QString GA, int type);

extern bool deleteRelationByDeviceIDAndCommObjectNumAndAddressNum(int deviceID, int relationID);

extern bool updateBuildingName(int buildingID, QString buildingName);

extern bool updateBuildingDescribe(int buildingID, QString describe);

extern bool updateBuildingNum(int buildingID, int num);

extern bool updateDeviceName(int deviceID, QString deviceName);

extern bool updateDevicePA(int deviceID, QString devicePA);

extern bool updateDeviceDescribe(int deviceID, QString describe);

extern bool updateAddressName(int id, QString addressName);

extern bool updateAddressDescribe(int id, QString describe);

extern bool updateAddressIDAndAddressNumAndEepromAddressToOrder(int deviceID, int addressID);

extern bool updateRelationIDAndEepromAddressByDeviceIDAndRelationID(int deviceID, int relationID);

extern bool updateRelationDescribeByDeviceIDAndObjectNum(int deviceID, int commObjectNum, QString describe);

extern bool updateRelationGAByDeviceIDAndCommObjectNum(int deviceID, int commObjectNum, QString relationGA);

extern bool updateRelationGAAndDescribeNullByCommObjectNumAndDeviceID(int deviceID, int commObjectNum);

extern bool updateInterfaceValueByDeviceIDAndInterfaceObjectNum(int deviceID, int interfaceObjectNum, int value);

extern bool updateAllTableProductIDAndDeviceID(int productID, int deviceID);

extern QVariant selectBySql(QString sql);

extern int selectNextBuildingID();

extern int selectBuildingIDByName(QString name);

extern QString selectBuilgingNameByID(int buildingID);

extern int selectNextDeviceID();

extern int selectDeviceIDByName(QString name);

extern QString selectDeviceNameByID(int deviceID);

extern int selectNextAddressID();

extern int selectIDByAddressAndType(QString address, int type);

extern int isDeviceNameExist(QString deviceName);

extern int isAddressValueExist(int value, int type);

extern int selectNextDeviceAddressIDByDeviceID(int deviceID);

extern int selectNextGroupEepromAddressByDeviceID(int deviceID);

extern int selectNextAddressNumByDeviceID(int deviceID);

extern QString selectAddressNameByDeviceIDAndGA(int deviceID, QString GA);

extern int selectNextRelationIDByDeviceID(int deviceID);

extern int selectNextRelationNumByDeviceID(int deviceID);

extern int selectNextEepromAddressByDeviceID(int deviceID);

extern int selectDeviceIDByPA(QString PA);

extern int selectInterfaceObjectDataLenByDeviceID(int deviceID);

extern int selectCommObjectDataLenByDeviceID(int deviceID);

extern int selectAddressDataLenByDeviceID(int deviceID);

extern int selectRelationDataLenByDeviceID(int deviceID);

extern int selectInterfaceObjectTableEepromAddressBegin(int deviceID);

extern int selectCommObjectTableEepromAddressBegin(int deviceID);

extern int selectAddressTableEepromAddressBegin(int deviceID);

extern int selectRelationTableEepromAddressBegin(int deviceID);

extern uchar *selectInterfaceObjectDataByDeviceID(int deviceID, uchar *interfaceObjectTableData);

extern uchar *selectCommObjectDataByDeviceID(int deviceID, uchar *commObjectTableData);

extern uchar *selectAddressDataByDeviceID(int deviceID, uchar *addressTableData);

extern uchar *selectRelationDataByDeviceID(int deviceID, uchar *relationTableData);

extern int selectAddressIDByAddressAndTypeAndDeviceID(QString address, int type, int deviceID);

extern int selectAddressNumByAddressAndDeviceID(QString address, int deviceID);

extern int selectGroupEepromAddressByAddressAndDeviceID(QString address, int deviceID);

extern int selectRelationIDByDeviceIDAndCommObjectNumAndAddressNum(int deviceID, int commObjectNum, int addressNum);

extern int selectRelationNumByDeviceIDAndCommObjectNumAndAddressNum(int deviceID, int commObjectNum, int addressNum);

extern int selectRelationEepromAddressByDeviceIDAndCommObjectNumAndAddressNum(int deviceID, int commObjectNum, int addressNum);

extern int selectInterfaceObjectValueByDeviceIDAndInterfaceObjectNum(int deviceID, int interfaceObjectNum);

#endif // PROJECTDATABASAOPERATIONS_H
